<!-- 销售订单记录-详情 -->
<template>
  <div class="pagePadding">
    <Spin fix v-if="tabloading"></Spin>
    <Table :productList="listColumns" :productData="listData">
      <div slot="summary" class="summary" v-if="this.listData.length > 0">
        总数量：<span class="color389">{{ total_amount }}</span> 合计金额：<span class="color389">¥{{ total_price }}</span>
      </div>
    </Table>
  </div>
</template>

<script>
import Table from '@/components/table'

export default {
  name: 'detailsSalesOrderRecord',
  components: {
    Table,
  },
  computed: {
    totleMoney() {
      let totle = 0
      this.listData.forEach(item => {
        totle += item.money * item.num
      })
      return totle
    },
  },
  data() {
    return {
      tabloading: false,
      // 总数量
      total_amount: 0,
      // 合计金额
      total_price: 0,
      // 表格数据
      listData: [],
      // 表格头部标题
      listColumns: [
        {
          title: '序号',
          type: 'index',
          align: 'center',
          fixed: 'left',
          width: 55,
        },
        {
          title: '产品名称',
          key: 'product_name',
          align: 'center',
          minWidth: 150,
        },
        {
          title: '规格型号',
          key: 'product_model_name',
          align: 'center',
          minWidth: 80,
        },
        {
          title: '货号/SKU',
          key: 'c',
          align: 'center',
          minWidth: 80,
        },
        {
          title: '单位',
          key: 'product_unit',
          align: 'center',
          minWidth: 60,
        },
        {
          title: '数量',
          key: 'product_amount',
          align: 'center',
          minWidth: 60,
        },
        {
          title: '单价',
          align: 'center',
          minWidth: 80,
          render: (h, param) => {
            return h('span', '¥' + param.row.product_unit_price)
          },
        },
        {
          title: '金额',
          align: 'center',
          minWidth: 80,
          render: (h, param) => {
            return h('span', '¥' + param.row.product_total_price)
          },
        },
        {
          title: '生产厂家',
          key: 'factory_name',
          align: 'center',
          minWidth: 150,
        },
        {
          title: '生产企业许可证备案凭证',
          key: 'i',
          align: 'center',
          minWidth: 150,
        },
        {
          title: '注册证号/备案凭证号',
          key: 'licence_code',
          align: 'center',
          minWidth: 130,
        },
        {
          title: '购货单位',
          key: 'k',
          align: 'center',
          minWidth: 80,
        },
        {
          title: '购货单位许可证',
          key: 'l',
          align: 'center',
          minWidth: 110,
        },
        {
          title: '经营地址',
          key: 'm',
          align: 'center',
          minWidth: 130,
        },
        {
          title: '销售方式',
          key: 'n',
          align: 'center',
          minWidth: 80,
        },
        {
          title: '销售日期',
          key: 'order_time',
          align: 'center',
          minWidth: 80,
        },
      ],
    }
  },
  mounted() {
    this.getSaleOrderDetail()
  },
  methods: {
    getSaleOrderDetail() {
      this.tabloading = true
      this.$http.get(this.$api.saleOrderDetail, {order_code: this.$route.query.order_code}).then(res => {
       this.tabloading = false
       this.listData = res.data.order_detail
        let order_time = res.data.order_time ? this.$moment(res.data.order_time * 1000).format('YYYY-MM-DD') : ''
        this.listData.forEach(item => {
          item.order_time = order_time
        })
        
        this.total_amount = res.data.total_amount
        this.total_price = res.data.total_price
      })
    }
  },
}
</script>

<style></style>
